perm filename EINIT3.2[EAL,HE] blob sn#706591 filedate 1983-04-11 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	{$NOMAIN	Editor initialization (part of it) }
C00004 00003	(* routine to make predeclared identifiers & constants: initIdents *)
C00018 ENDMK
C⊗;
{$NOMAIN	Editor initialization (part of it) }

%include einit.hdr;

{ Externally defined routines from elsewhere: }

	(* From ALLOC *)
function newNode: nodep;					external;
function newToken: tokenp;					external;
function newIdent: identp;					external;
function newStrng: strngp;					external;
function newVaridef: varidefp;					external;

	(* From EAUX1A *)
function hash(ch: ascii): integer;				external;

(* routine to make predeclared identifiers & constants: initIdents *)

procedure init2Idents; external;
procedure init2Idents;
 var id: identp; v: varidefp; n: nodep; str: strngp;
     sfId,degId,secId: identp; t,tp: tokenp;	(* for macro defs *)

 function makeIdent(s: cstring): identp;
  var id: identp; str: strngp; i: integer;
  begin
  id := newIdent;
  with id↑ do
    begin
    predefined := nil;
    str := newStrng;
    str↑.ch := s;
    name := str;
    length := 10;
    while s[length] = ' ' do length := length - 1;
    end;
  i := hash(id↑.name↑.ch[1]);		(* find proper bucket *)
  id↑.next := idents[i];		(* link us onto list of identifiers *)
  idents[i] := id;
  makeIdent := id;
  end;

 function ConMake(s: cstring; d: datatypes; vdim: varidefp;
					    sv: real; n: nodep): identp;
  var id: identp; vdef: varidefp;
  begin
  id := makeIdent(s);
  vdef := newVaridef;
  id↑.predefined := vdef;
  if n = nil then	(* need to make up a new constant node *)
    begin
    n := newNode;
    with n↑ do
     begin
     next := nil;
     ntype := leafnode;
     ltype := d;
     if d = svaltype then s := sv;
     end;
    end;
  with vdef↑ do
   begin
   name := id;
   vtype := pconstype;
   dtype := vdim;
   offset := 0;
   tbits := 0;
   dbits := 0;
   c := n;
   dnext := nil;
   end;
  ConMake := id;
  end;

 function MacMake(s: cstring): identp;
  var id: identp; vdef: varidefp;
  begin
  id := makeIdent(s);
  vdef := newVaridef;
  id↑.predefined := vdef;
  vdef↑.name := id;
  vdef↑.vtype := macargtype;
  MacMake := id;
  end;

 function CToken(num: real; tp: tokenp): tokenp;
  var t: tokenp; n: nodep;
  begin
  t := newToken;
  if tp <> nil then tp↑.next := t;
  n := newNode;
  t↑.ttype := constype;
  t↑.cons := n;
  n↑.ntype := leafnode;
  n↑.ltype := svaltype;
  n↑.s := num;
  CToken := t;
  end;

 function IToken(i: identp; tp: tokenp): tokenp;
  var t: tokenp;
  begin
  t := newToken;
  if tp <> nil then tp↑.next := t;
  t↑.ttype := identtype;
  t↑.id := i;
  IToken := t;
  end;

 function RToken(r: reswdtypes): tokenp;
  var t: tokenp;
  begin
  t := newToken;
  t↑.ttype := reswdtype;
  t↑.rtype := r;
  RToken := t;
  end;

 function WithToken(tp: tokenp): tokenp;
  var t: tokenp;
  begin
  t := RToken(filtype);
  if tp <> nil then tp↑.next := t;
  t↑.filler := withtype;
  WithToken := t;
  end;

 function OpToken(tp: tokenp): tokenp;
  var t: tokenp;
  begin
  t := RToken(optype);
  if tp <> nil then tp↑.next := t;
  t↑.op := seqop;
  OpToken := t;
  end;

 function ClToken(cl: clsetypes; tp: tokenp): tokenp;
  var t: tokenp;
  begin
  t := RToken(clsetype);
  if tp <> nil then tp↑.next := t;
  t↑.clause := cl;
  ClToken := t;
  end;

 function FilToken(fil: filtypes; tp: tokenp): tokenp;
  var t: tokenp;
  begin
  t := RToken(filtype);
  if tp <> nil then tp↑.next := t;
  t↑.filler := fil;
  FilToken := t;
  end;

 procedure SpdSt(id: identp; spd: real);
  var t,tp: tokenp;
  begin
  t := IToken(sfId,nil);
  id↑.predefined↑.marg := t;
  tp := RToken(stmnttype);
  t↑.next := tp;
  tp↑.stmnt := assigntype;
  t := CToken(spd,tp);
  t↑.next := nil;
  end;

 procedure SpdCl(id: identp; spd: real);
  var t,tp: tokenp;
  begin
  t := WithToken(nil);
  id↑.predefined↑.marg := t;
  tp := IToken(sfId,t);
  t := OpToken(tp);
  tp := CToken(spd,t);
  tp↑.next := nil;
  end;

 procedure SwtCl(id: identp; swt: real);
  var t,tp: tokenp;
  begin
  t := WithToken(nil);
  id↑.predefined↑.marg := t;
  tp := ClToken(stopwaittimetype,t);
  t := OpToken(tp);
  tp := CToken(swt,t);
  tp↑.next := nil;
  end;

 begin					(* now make up the constants *)
 id := ConMake('RPARK     ',transtype,distancedim,0.0,nil);
 id↑.predefined↑.c↑.t := rpark;
 id := ConMake('GPARK     ',transtype,distancedim,0.0,nil);
 id↑.predefined↑.c↑.t := gpark;
 id := ConMake('NILTRANS  ',transtype,distancedim,0.0,nil);
 n := id↑.predefined↑.c;
 n↑.t := niltrans;
 id := ConMake('NILROT    ',transtype,angledim,0.0,n);
 id := ConMake('STATION   ',transtype,distancedim,0.0,n);
 id := ConMake('XHAT      ',vectype,nodim,0.0,nil);
 id↑.predefined↑.c↑.v := xhat;
 id := ConMake('YHAT      ',vectype,nodim,0.0,nil);
 id↑.predefined↑.c↑.v := yhat;
 id := ConMake('ZHAT      ',vectype,nodim,0.0,nil);
 id↑.predefined↑.c↑.v := zhat;
 id := ConMake('NILVECT   ',vectype,nodim,0.0,nil);
 id↑.predefined↑.c↑.v := nilvect;
 id := ConMake('TRUE      ',svaltype,nodim,1.0,nil);
 n := id↑.predefined↑.c;
 degId := ConMake('DEG       ',svaltype,angledim,0.0,n);
 id := ConMake('DEGREES   ',svaltype,angledim,0.0,n);
 id := ConMake('INCH      ',svaltype,distancedim,0.0,n);
 id := ConMake('INCHES    ',svaltype,distancedim,0.0,n);
 id := ConMake('OUNCES    ',svaltype,forcedim,0.0,n);
 id := ConMake('OZ        ',svaltype,forcedim,0.0,n);
 secId := ConMake('SEC       ',svaltype,timedim,0.0,n);
 id := ConMake('SECOND    ',svaltype,timedim,0.0,n);
 id := ConMake('SECONDS   ',svaltype,timedim,0.0,n);
 id := ConMake('FALSE     ',svaltype,nodim,0.0,nil);
 id := ConMake('CM        ',svaltype,distancedim,0.3937008,nil);
 id := ConMake('GM        ',svaltype,forcedim,0.035274,nil);
 id := ConMake('RADIANS   ',svaltype,angledim,57.295779,nil);
 id := ConMake('PI        ',svaltype,nodim,3.1415927,nil);
 id := ConMake('LBS       ',svaltype,forcedim,16.0,nil);
 id := ConMake('RPM       ',svaltype,angveldim,6.0,nil);
 id := ConMake('CRLF      ',strngtype,nodim,0.0,nil);
 str := newStrng;
 str↑.ch[1] := chr(15B); (* cr *)
 str↑.ch[2] := chr(12B); (* lf *)
 id↑.predefined↑.c↑.str := str;
 id↑.predefined↑.c↑.length := 2; 
 id := ConMake('PANIC_BUTT',svaltype,nodim,1024.0,nil);	(* '2000 *)
 id↑.name↑.next := newStrng;
 id↑.name↑.next↑.ch := 'ON        '; 
 id↑.length := 12; 
 id := ConMake('EXCESSIVE_',svaltype,nodim,2048.0,nil);	(* '4000 *)
 id↑.name↑.next := newStrng;
 id↑.name↑.next↑.ch := 'FORCE     '; 
 id↑.length := 15; 
 id := ConMake('TIME_OUT  ',svaltype,nodim,4096.0,nil);	(* '10000 *)

 id := MacMake('DIRECTLY  ');		(* now make predeclared macros *)
 t := WithToken(nil);			(*   "WITH APPROACH = NILDEPROACH" *)
 id↑.predefined↑.marg := t;
 tp := ClToken(approachtype,t);
 t := OpToken(tp);
 tp := ClToken(nildeproachtype,t);
 t := WithToken(tp);			(*   "WITH DEPARTURE = NILDEPROACH" *)
 tp := ClToken(departuretype,t);
 t := OpToken(tp);
 tp := ClToken(nildeproachtype,t);
 tp↑.next := nil;
 v := sysVars;				(* need to find ident for speedfactor *)
 while v↑.next <> nil do v := v↑.next;  (* fortunately it's the last one *)
 sfId := v↑.name;
 SpdSt(MacMake('QUICK     '),1.0);	(* QUICK = "SPEEDFACTOR := 1.0" *)
 SpdSt(MacMake('SLOW      '),3.0);	(* SLOW = "SPEEDFACTOR := 3.0" *)
 SpdSt(MacMake('CAUTIOUS  '),4.0);	(* CAUTIOUS = "SPEEDFACTOR := 4.0" *)
 SpdCl(MacMake('QUICKLY   '),1.0);	(* QUICKLY = "WITH SPEEDFACTOR = 1.0" *)
 SpdCl(MacMake('NORMALLY  '),2.0);	(* NORMALLY = "WITH SPEEDFACTOR = 2.0" *)
 SpdCl(MacMake('SLOWLY    '),3.0);	(* SLOWLY = "WITH SPEEDFACTOR = 3.0" *)
 SpdCl(MacMake('CAUTIOUSLY'),4.0);	(* CAUTIOUSLY = "WITH SPEEDFACTOR = 4.0" *)
 id := MacMake('APPROXIMAT');
 id↑.name↑.next := newStrng;
 id↑.name↑.next↑.ch := 'ELY       '; 
 id↑.length := 13; 
 t := WithToken(nil);			(* APPROXIMATELY = "WITH NO NULLING" *)
 id↑.predefined↑.marg := t;
 tp := RToken(filtype);
 t↑.next := tp;
 tp↑.filler := notype;
 t := ClToken(nullingtype,tp);
 t↑.next := nil;
 id := MacMake('PRECISELY ');
 t := WithToken(nil);			(* PRECISELY = "WITH NULLING" *)
 id↑.predefined↑.marg := t;
 tp := ClToken(nullingtype,t);
 tp↑.next := nil;
 id := MacMake('LINEARLY  ');
 t := WithToken(nil);			(* LINEARLY = "WITH LINEAR MOTION" *)
 id↑.predefined↑.marg := t;
 tp := ClToken(lineartype,t);
 t := RToken(filtype);
 tp↑.next := t;
 t↑.filler := motiontype;
 t↑.next := nil;
 SwtCl(MacMake('GENTLY    '),0.0);	(* GENTLY = "WITH STOPWAITTIME = 0.0" *)
 SwtCl(MacMake('TIGHTLY   '),0.5);	(* TIGHTLY = "WITH STOPWAITTIME = 0.5" *)
 id := MacMake('TIL       ');
 t := filToken(steptype,nil);		(* TIL = "STEP 1 UNTIL" *)
 id↑.predefined↑.marg := t;
 tp := CToken(1.0,t);
 t := filToken(untltype,tp);
 t↑.next := nil;
 end;